<template>
	<view class="container">
		<view class="flexcenter" style="margin-top: 100rpx;">
			<image src="@/static/logo.png" style="width: 440rpx;height: 400rpx;" mode=""></image>
		</view>
		<view class="name flexcenter"> 會員登入 </view>
		<view class="item">
			<view class="left">行動電話</view>
			<input type="number" v-model="mobile"  placeholder-style="color:#999" class="ipt"
				placeholder="輸入您的行動電話" />
		</view>
		<!-- 驗證碼 -->
		<view class="item">
			<view class="left">密碼</view>
			<input type="password" v-model="password" maxlength="12" class="ipt" placeholder-style="color:#999"
				placeholder="6-12位字母數字組合" />
		</view>
		<view class="fora">
			<view @click="register()">忘記密碼？</view>
			<view class="lv_text" style="color: #41a863;" @click="jumpurl('/pages/caozuoshouce/shiyongsc?type=1')">操作手冊</view>
		</view>
		<view class="btn" @tap="userLogin">登入</view>
		<view class="zw titletext" @click="ref()"> 暫無帳號，請注冊> </view>
		<view class="ysxy">
			<view>
				登入註冊即代表同意
				<text @click="goyhxy()">《用戶協議》</text>
				和<text @click="gouserAgreement()">《隱私政策》</text>
			</view>
		</view>
	</view>
</template>

<script>
	import WebSocket from '@/common/websocket.js' //websocket封装
	export default {
		data() {
			return {
				mobile: "", //帳號
				password: "", //密碼
				isClick: true,
				codeTime: 60, //倒計时時間
				code: "", //驗證碼
				isshow: false,
				websocket:null
			};
		},
		onLoad() {},
		methods: {
			goyhxy() {
				uni.navigateTo({
					url: "./userAgreement/yhxy",
				});
			},
			gouserAgreement() {
				uni.navigateTo({
					url: "./userAgreement/userAgreement",
				});
			},
			//去註冊
			ref() {
				uni.navigateTo({
					url: "/pages_login/register",
				});
			},
			//改密碼
			register() {
				uni.navigateTo({
					url: "/pages_login/forgetPwd"
				});
			},
			//手機號登錄
			forget() {
				uni.navigateTo({
					url: "/pages_login/codeLogin",
				});
			},
			// 點擊登錄按钮
			userLogin() {
				this.codeLogin();
			},
			async codeLogin() { //密碼登錄
				if (this.mobile=="") {
					this.http.toast("請輸入您的行動電話")
					return false
				}
				if (!this.password) {
					this.http.toast("請輸入正確的密碼")
					return false
				}
				let res=await this.http.request('/api/user/login', 'POST', {
					mobile: this.mobile,
					password:this.password
				})
				if (res.code == 1) {
					this.http.toast(res.msg);
					let userinfo = res['data']['userinfo'];
					// 存
					uni.setStorageSync('token', userinfo['token']);
					uni.setStorageSync('user_id', userinfo['user_id']);
					this.websocketStart()
					setTimeout(() => {
						uni.navigateBack(1)
					}, 1000)
				}else{
					this.http.toast(res.msg);
				}
			},
			websocketStart() {
				this.websocket = new WebSocket("wss://useradmin.opos.tw:8282");
				this.websocket.connect()
				this.websocket.onMessage(result => {
					console.log('app.js收到服務器内容：' +result.data);
					uni.$emit('updatechatFn', "")
					uni.$emit('updatechatFnList', "")
				})
			},
		},
	};
</script>

<style scoped lang="scss">
	.ysxy {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 80%;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: 80rpx;
		color: #999999;
		font-size: 24rpx;

		text {
			color: #FFB800;
		}
	}

	.container {
		background-color: #ffffff !important;
		position: relative;
		overflow: hidden;
		height: 100vh;
	}

	::v-deep .uni-checkbox-input {
		margin-right: 10rpx;
		-webkit-appearance: none;
		appearance: none;
		outline: 0;
		border: 1px solid #d1d1d1;
		background-color: #fff;
		border-radius: 50%;
		width: 32rpx;
		height: 32rpx;
		position: relative;
		color: #007aff;
	}

	::v-deep .uni-switch-input-checked {
		background-color: #ff7400;
		border-color: #ff7400;
		display: none;
	}

	::v-deep .uni-checkbox-input-checked {
		color: #ff7400;
	}

	.login-bg {
		width: 750rpx;
		height: 441rpx;
		position: absolute;
		top: 0;
		left: 0;
		overflow: hidden;
	}

	.name {
		text-align: left;
		margin: 30rpx 30rpx 10rpx;
		font-size: 38rpx;
		font-weight: 550;
	}

	// 每個form项
	.item {
		width: 670rpx;
		height: 120rpx;
		margin: 0rpx auto 0;
		display: flex;
		align-items: center;
		overflow: hidden;
		border-bottom: 2rpx solid #efefef;

		.shu {
			color: #cccccc;
		}

		.left {
			width: 130rpx;
			margin: 37rpx 0;
			text-align: center;
			font-size: 30rpx;
			font-weight: 400;
			color: #111;
			border-right: 2rpx solid #cccccc;
		}

		.text {
			font-size: 28rpx;
			font-weight: 400;
			line-height: 33rpx;
			color: #333;
			opacity: 1;
			margin-left: 35rpx;
		}

		.ipt {
			margin-left: 16rpx;
			flex: 1;
			border: 0 none;
			font-size: 32rpx;
			font-weight: 400;
		}

		.icon {
			position: absolute;
			right: 0;
			top: 2rpx;
			bottom: 33rpx;
			width: 38rpx;
			height: 38rpx;
		}
	}

	.fora {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 5rpx 40rpx;

		view {
			margin-top: 20rpx;
			color: #FFB800;
		}
	}

	// 註冊按钮
	.register-box {
		display: flex;
		justify-content: flex-end;
		width: 600rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin: 0 auto;

		.register-btn {
			font-size: 24rpx;
			font-weight: 500;
			height: 100%;
		}
	}

	// 登錄按钮
	.btn {
		margin: 30rpx auto 0;
		width: 670rpx;
		height: 95rpx;
		background: #FFB800;
		border-radius: 50rpx;
		font-size: 32rpx;
		font-weight: 400;
		text-align: center;
		line-height: 95rpx;
		color: #000000;
	}

	// quickLogin end
	.wx-btn {
		margin-top: 40rpx;
		justify-content: center;
		text-align: center;

		.img {
			width: 100rpx;
			height: 100rpx;
		}

		.wx-txt {
			font-size: 24rpx;
			font-weight: 400;
			line-height: 80rpx;
			color: #7a7c94;
			opacity: 1;
		}
	}

	.zw {
		text-align: center;
		color: #3e5c92;
		margin-top: 15rpx;
	}
</style>